<?php

class PdfHelper extends AppHelper {
	var $helpers = array('Html');
	var $lib = null;
	function __construct() {
		parent::__construct();
		App::import('Vendor','DOMPDF',array('file' => 'dompdf/dompdf_config.inc.php'));
		$this->lib = new DOMPDF();
	}

	function load_html($html) {
		$this->lib->load_html($html);
	}

	function set_paper($size='A4',$orientation='portrait') {
		$this->lib->set_paper($size,$orientation);
	}

	function render() {
		$this->lib->render();
	}

	function stream($name) {
		$this->lib->stream($name,array("Attachment" => 0));
	}

	function css($path, $rel = null, $htmlAttributes = array(),$inline=true) {
		$link = $this->Html->css($path,$rel,$htmlAttributes);
		$link = preg_replace('/href=\"/','href="http://'.env('HTTP_HOST'),$link);
		if(!$inline) {
			$view =& ClassRegistry::getObject('view');
			$view->addScript($link);
		}
		else
		return $link;
	}

	function image($path,$options=array()) {
		$img = $this->Html->image($path,$options);
		return preg_replace('/src=\"/','src="http://'.env('HTTP_HOST'),$img);
	}
}
?>